package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/10 17:11
 * https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/
 */
public class Title230 {

    class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode() {
        }

        public TreeNode(int val) {
            this.val = val;
        }

        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    int count;
    int result;

    public int kthSmallest(TreeNode root, int k) {
        count = 0;
        result = 0;
        dfs(root, k);
        return result;
    }

    private void dfs(TreeNode root, int k) {
        //中序遍历
        if (root == null) {
            return;
        }
        dfs(root.left, k);
        count++;
        if (count == k) {
            result = root.val;
            return;
        }
        dfs(root.right, k);
    }

    public static void main(String[] args) {
        char[][] temp = {{'X', 'O', 'O', 'X'}, {'X', 'O', 'X', 'X'}, {'X', 'X', 'X', 'X'}, {'X', 'O', 'X', 'X'}};

    }
}
